/*
 *
 *  * Copyright:  2018 smarabbit studio.
 *  *
 *  *  Licensed under the Confluent Community License; you may not use this file
 *  *  except in compliance with the License.  You may obtain a copy of the License at
 *  *
 *  *  http://www.confluent.io/confluent-community-license
 *  *
 *  *  Unless required by applicable law or agreed to in writing, software
 *  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  *  WARRANTIES OF ANY KIND, either express or implied.  See the License for the
 *  *  specific language governing permissions and limitations under the License.
 *  *
 *  *  @作   者： 黄开晖 (117227773@qq.com)
 *  *  @日   期:    ${DATE}
 *
 */

/**
 * 
 */
package com.massyframework.beanskin.util.sorting.graph;

import java.util.List;
import java.util.function.Predicate;

/**
 * {@link Graph},图
 * @author huangkh
 *
 */
public interface Graph<T> {
    
	/**
	 * 顶点的数量
	 * @return {@link int}
	 */
    int vertexNumber();
    
    /**
     * 判断数据是否存在
     * @param data {@link T}
     * @return {@link boolean},返回{@code true}表示存在，否则返回{@code false}
     */
    boolean exist(T data);
    
    /**
     * 插入数据
     * <br>
     * 如果数据已经存在，则返回{@code false}
     * @param data {@link T}
     * @return {@link boolean},返回{@code true}表示成功，否则返回{@code false}.
     */
    boolean insert(T data);
    
    /**
     * 移除数据并返回对应的顶点
     * @param data {@link T},数据
     * @return {@link Vertex}，可能返回null.
     */
    Vertex<T> remove(T data);
    
    /**
     * 移除所有满足{@code filter}的顶点
     * @param filter {@link Predicate},过滤条件
     * @return {@link List}
     */
    List<T> remove(Predicate<Vertex<T>> filter);
    
    /**
     * 根据数据查找对应的顶点
     * @param data {@link T},数据
     * @return {@link Vertex},可能返回null.
     */
    Vertex<T> find(T data);
        
    /**
     * 边的数量
     * @return {@link int}
     */
    int edgeNumber();
    
    /**
     * 判断{@code data1}和{@code data2}是否同时存在
     * @param data1 {@link T},数据1
     * @param data2 {@link T},数据2
     * @return {@link boolean},返回{@code true}表示同时存在，否则返回{@code false}
     */
    boolean exist(T data1, T data2);
    
    /**
     * 插入数据1和数据2的边
     * @param data1 {@link T},数据1
     * @param data2 {@link T},数据2
     * @param edge {@link Edge},边
     * @return {@link boolean},返回{@code true}表示成功，返回{@code false},表示失败
     */
    boolean insert(T data1, T data2, Edge edge);
    
    /**
     * 移除{@code data1}和{@code data2}的边
     * @param data1 {@link T},数据1
     * @param data2 {@link T},数据2
     * @return {@link Edge}
     */
    Edge remove(T data1, T data2);
    
    /**
     * 查找{@code data1}和{@code data2}的边
     * @param data1 {@link T},数据1
     * @param data2 {@link T},数据2
     * @return {@link Edge},可能返回null.
     */
    Edge find(T data1, T data2);

    
    /**
     * 使用深度优先搜索(bfs}进行处理
     * @param data {@link T}
     * @param function {@link Function}
     */
    void bfs(T data, Function<T> function);
    
    /**
     * 
     * @param vertex
     * @param function
     */
    void dfs(T vertex, Function<T> function);
}
